package com.restaurant.application.login.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class LoginPageData implements PickableBean {

    public static final String FN_LOGINPATH = "loginPath";
    public static final String FN_ERRORMESSAGE = "errorMessage";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_LOGINPATH,
            FN_ERRORMESSAGE);

    private String loginPath;
    private String errorMessage;

    public LoginPageData(String loginPath, String errorMessage) {
        setLoginPath(loginPath);
        setErrorMessage(errorMessage);
    }

    public LoginPageData() {
    }

    public LoginPageData duplicate() {
        LoginPageData result = new LoginPageData();
        result.loginPath = this.loginPath;
        result.errorMessage = this.errorMessage;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getLoginPath() {
        return loginPath;
    }

    public void setLoginPath(String value) {
        this.loginPath = value;
    }

    public LoginPageData withLoginPath(String value) {
        setLoginPath(value);
        return this;
    }

    public LoginPageData withLoginPath(String value, String defaultValue) {
        setLoginPath(value == null ? defaultValue : value);
        return this;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String value) {
        this.errorMessage = value;
    }

    public LoginPageData withErrorMessage(String value) {
        setErrorMessage(value);
        return this;
    }

    public LoginPageData withErrorMessage(String value, String defaultValue) {
        setErrorMessage(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "loginPath":
                return getLoginPath();
            case "errorMessage":
                return getErrorMessage();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof LoginPageData)) return false;
        return signature().equals(((LoginPageData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean LoginPageData has no signature defined, no hash code or equals possible.");
    }
}
